package com.wangyadong.hobby.schedule.jobtask.dsa;

class Skiplist {


    static final Node HEAD = new Node(-1, null);

    static class Node {
        private int val;
        private Node next;
        private Node down;

        public Node(int val, Node next) {
            this.next = next;
            this.val = val;
        }
    }

    public Skiplist() {

    }

    public boolean search(int target) {
        boolean exits = false;
        Node head = HEAD;
        while (head != null && head.val < target) {
            Node next = head.next;
            while (next != null && next.val < target) {
                next = head.next;
            }
            if (next != null && next.val == target) {
                return true;
            }
            head = head.down;
        }
        return exits;
    }

    public void add(int target) {
        Node head = HEAD;
        while (head!=null && head.val<target){

        }

    }

    /**
     * 删除
     *
     * @param target
     * @return
     */
    public boolean erase(int target) {
        boolean exits = false;
        Node head = HEAD;
        while (head != null && head.val < target) {
            Node next = head.next;
            while (next != null && next.val < target) {
                next = head.next;
            }
            if (next != null && next.val == target) {
                next.next = null;
                next.down = null;
            }
            head = head.down;
        }
        return exits;
    }
}
